export default ({ app, req, route }) => {
  const notRoute = /map$/g.test(route.path)
  if (notRoute) { return }

  let userAgent = ''
  if (process.server) { userAgent = req.headers['user-agent'] }
  if (process.client) { userAgent = navigator.userAgent }
  app.$isPc = getClientType(userAgent) === 'PC'
}

function getClientType (userAgent) {
  const isAndroid = userAgent.indexOf('Android') > -1 || userAgent.indexOf('Adr') > -1
  const isiOS = !!userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
  let clientType = 'PC'
  if (isAndroid) { clientType = 'Android' }
  if (isiOS) { clientType = 'IOS' }
  return clientType
}
